import PageModel from "../../models/Page";
import Crypt from "../../utils/Crypt";
import config from "../../config/config";

const pageModel = new PageModel()

Page({
  data: {
    page: 0,
    pageSize: 10,
    list: [],
    busy: false,
    baseUrl: config.app_base_url
  },
  onLoad: function (options) {
    // this._getList()
    wx.navigateTo({
      url: '/pages/login/index'
    })
  },

  onReachBottom() {
    // this._getList(true)
  },

  _getList(append = false) {
    if (this.data.busy === false) {
      this.setData({
        busy: true,
        page: this.data.page + 1
      })
      pageModel.materialList({ ...this.data }).then(response => {
        let { data } = response
        data = Crypt.parse(data)
        if (data.list.length === 0) {
          this.setData({ busy: true })
        } else {
          this.setData({ busy: false })
          if (append) {
            this.setData({ list: this.data.list.concat(data.list) })
          } else {
            this.setData({ list: data.list })
          }
        }

        console.log(this.data.list)

      })
    }
  },


  previewImage(e) {
    const current = e.currentTarget.dataset.src
    wx.previewImage({
      current: current,
      urls: [current]
    })
  },


  // index.js
  copyText(e) {
    let key = e.currentTarget.dataset.key;
    wx.setClipboardData({ //设置系统剪贴板的内容
      data: key,
      success(res) {
        console.log(res, key);
        wx.getClipboardData({ // 获取系统剪贴板的内容
          success(res) {
            wx.showToast({
              title: '复制成功',
            })
          }
        })
      }
    })
  }



});
